package com.stock.controller;

import com.stock.entity.UserEntity;
import com.stock.service.IUserService;
import com.stock.vo.ResultVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user")
@CrossOrigin(origins = "*")
@Api(tags = "用户管理")
public class UserController {

    private final IUserService userService;

    public UserController(IUserService userService) {
        this.userService = userService;
    }

    @PostMapping("/login")
    @ApiOperation("登录")
    public ResultVo login(@RequestBody UserEntity user) {
        return userService.login(user);
    }

    @PostMapping("/register")
    @ApiOperation("注册")
    public ResultVo register(@RequestBody UserEntity user) {
        return userService.register(user);
    }

    @GetMapping("/getCurrentUserPoint")
    @ApiOperation("获取当前用户的积分")
    public ResultVo getCurrentUserPoint() {
        return ResultVo.success(userService.getCurrentUserPoint());
    }

}
